package me.sealer.ssm.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 功能描述： $ CorsConfig
 *
 * @author sealer
 * @email 1178884049@qq.com
 * @date 2019年12月20日 16时40分17秒
 */
@Component
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Value("${sealer.cors.allowedOrigins}")
    private String[] allowedOrigins;

    @Value("${sealer.cors.allowedMethods}")
    private String[] allowedMethods;

    @Value("${sealer.cors.allowCredentials}")
    private boolean allowCredentials;

    @Value("${sealer.cors.maxAge}")
    private Long maxAge;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins(allowedOrigins)
                .allowCredentials(allowCredentials)
                .allowedMethods(allowedMethods)
                .maxAge(maxAge);
    }
}
